//
//  My_Setting.m
//  HappyStore
//
//  Created by 点点充 on 16/1/25.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "My_Setting.h"

@interface My_Setting ()

@end

@implementation My_Setting

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    self.tabBarController.tabBar.hidden = YES;
    self.navigationController.navigationBarHidden = NO;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 190, 44)];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.font = [UIFont systemFontOfSize:19];
    titleLabel.text = @"设置";
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLabel;
    
    //设置返回按钮
    UIBarButtonItem *leftItem = [UIBarButtonItem itemWithTarget:self action:@selector(leftBarButtonItemClick) image:@"Back" highImage:@"Back"];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    //开启侧滑
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    
}
-(void)leftBarButtonItemClick{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return 141;
    }else if(indexPath.row == 4) {
        return 230;
    }else {
        return 44;
    }
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellTop = @"cellTop";
    static NSString *cellCenter = @"cellCenter";
    static NSString *cellBottom = @"cellBottom";
    
    UITableViewCell *cell;
    if (indexPath.row == 0) {
        cell = [tableView dequeueReusableCellWithIdentifier:cellTop forIndexPath:indexPath];
    }else if (indexPath.row == 4) {
        cell = [tableView dequeueReusableCellWithIdentifier:cellBottom forIndexPath:indexPath];
        //注销
        UIButton *btnOutLogin = [cell viewWithTag:10];
        btnOutLogin.layer.masksToBounds = YES;
        btnOutLogin.layer.cornerRadius = 5.f;
        [btnOutLogin addTarget:self action:@selector(btnClickOutLogin) forControlEvents:UIControlEventTouchUpInside];
        
    }else {
        cell = [tableView dequeueReusableCellWithIdentifier:cellCenter forIndexPath:indexPath];
        
        //                                        @"btn_my_shiming"];      @"btn_my_yinjian",@"btn_my_jilu",@"icon_beiyaoqing",@"btn_my_vip",

        
        NSArray *aryImgname = @[@"icon-xiugaimima.png",@"icon_lingsheng.png",@"icon_fankui.png"];
        UIImageView *imgView = [cell viewWithTag:10];
        imgView.image = [UIImage imageNamed:aryImgname[indexPath.row -1]];
        
        NSArray *aryTitle = @[@"修改密码",@"铃音通知",@"反馈"];
        UILabel *labTitle = [cell viewWithTag:11];
        labTitle.text = aryTitle[indexPath.row -1];
        
        //按钮13  箭头12
        UIImageView *imgJiantou = [cell viewWithTag:12];
        
        UISwitch *switchOk = [cell viewWithTag:13];
        
        if (indexPath.row == 2) {
            switchOk.hidden = NO;
            [switchOk addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
            imgJiantou.hidden = YES;
        }else {
            switchOk.hidden = YES;
            imgJiantou.hidden = NO;
        }
        
        
    }
    
    [cell setFrame:CGRectMake(0, 0, screenW, 44)];
    
    return cell;
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];//取消选中状态
    
    //取消显示后退键文字
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = barButtonItem;
    
    switch (indexPath.row) {
//        case 1://成为VIP
//        {

//        }
//            break;
        case 1://修改密码
        {
            UIStoryboard *LoginAndRegister = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            ForgetPassWord *ForgetPassWord = [LoginAndRegister instantiateViewControllerWithIdentifier:@"forgetpassword"];
            [self.navigationController pushViewController:ForgetPassWord animated:YES];
            
        }
            break;
        case 2://铃音通知
        {
            
        }
            break;
        case 3://反馈
        {
            [self performSegueWithIdentifier:@"myFankui" sender:self];
        }
            break;
        default:
            break;
    }
    
    
    
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // segue.identifier：获取连线的ID
    if ([segue.identifier isEqualToString:@"project_detail"]) {
//        Project_Detail *result = segue.destinationViewController;
//        result.projectId = strProjectId;
    }
}

#pragma mark - 开关
-(void)switchAction:(id)sender
{
    UISwitch *switchButton = (UISwitch*)sender;
    BOOL isButtonOn = [switchButton isOn];
    if (isButtonOn) {//开
        
    }else {//关
        
    }
}



#pragma mark - 注销
- (void)btnClickOutLogin
{

//    [self resetDefaults];
    [USER_DEFAULTS setObject:@"1" forKey:@"token"];
    [USER_DEFAULTS removeObjectForKey:@"userid"];
    [USER_DEFAULTS removeObjectForKey:@"token"];
    [USER_DEFAULTS removeObjectForKey:@"industry"];
    [USER_DEFAULTS removeObjectForKey:@"imToken"];
    [USER_DEFAULTS removeObjectForKey:@"userName"];
    [USER_DEFAULTS removeObjectForKey:@"phone"];
    [USER_DEFAULTS removeObjectForKey:@"userid"];
    [USER_DEFAULTS removeObjectForKey:@"account"];
    [USER_DEFAULTS removeObjectForKey:@"usertype"];
    [USER_DEFAULTS removeObjectForKey:@"password"];
    [USER_DEFAULTS removeObjectForKey:@"address"];
    [USER_DEFAULTS removeObjectForKey:@"imToken"];
    [USER_DEFAULTS removeObjectForKey:@"headPhoto"];
    [USER_DEFAULTS removeObjectForKey:@"account"];
    [USER_DEFAULTS removeObjectForKey:@"vipLevel"];
    [USER_DEFAULTS synchronize];


    [[RCIMClient sharedRCIMClient]
     logout];
    allConstMemberToken = nil;
    allConstMemberid = nil;
    
    [self.navigationController popViewControllerAnimated:YES];
    [self.delegate dismissControll];
}

- (void)resetDefaults
{
    NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
    NSDictionary* dict = [defs dictionaryRepresentation];
    for(id key in dict) {
        [defs removeObjectForKey:key];
    }
    [defs synchronize];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
